package top.frsf.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import top.frsf.entity.Provinceofchina;
import top.frsf.entity.Visit;
import top.frsf.service.PatientService;
import top.frsf.service.ProvinceofchinaService;
import top.frsf.service.VisitService;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author FRSF
 * @Date 2022/6/29 16:54
 * @Description
 **/

@Controller
@RequestMapping(value = "/patient")
public class PatientController {
    @Autowired
    private PatientService patientService;
    @Autowired
    private ProvinceofchinaService provinceofchinaService;
    @Autowired
    private VisitService visitService;

    //  Ajax异步请求数据
    @GetMapping(value = "/getmapdata")
    @ResponseBody
    public List<Provinceofchina> getPatientList() {
        return provinceofchinaService.getAll();
    }

    //  thymeleaf模板
    @RequestMapping("/map")
    public ModelAndView getMap() {
        ModelAndView modelAndView = new ModelAndView();
        Map<String, Object> map = new HashMap<>();
        map.put("recovery", patientService.getCure());
        map.put("die_num", patientService.getDie());
        modelAndView.setViewName("data");
        modelAndView.addObject("visit_num", visitService.getVisitCount());
        modelAndView.addObject("resultData", map);
        return modelAndView;
    }
}
